package com.inputabc.ct.v1.ui.inputbox.component;

import javax.swing.*;
import java.awt.*;
import java.awt.geom.RoundRectangle2D;

public class InputBoxMainPanel extends JPanel {
    private InputBoxScrollPane inputBoxScrollPane;
    
    // 定义配色
    private static final Color BG_COLOR = new Color(250, 250, 250);
    private static final Color BORDER_COLOR = new Color(230, 230, 230);
    
    // 圆角大小
    private static final int CORNER_RADIUS = 15;
    
    {
        setName(this.getClass().getName());
        inputBoxScrollPane = new InputBoxScrollPane();
    }
    
    public InputBoxMainPanel() {
        // 使用更高级的布局
        setLayout(new BorderLayout(5, 5));
        add(inputBoxScrollPane, BorderLayout.CENTER);
        
        // 设置透明背景以支持圆角
        setOpaque(false);
        
        // 设置面板边距
        setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    }
    
    /**
     * 重写绘制方法，添加圆角和阴影
     */
    @Override
    protected void paintComponent(Graphics g) {
        Graphics2D g2d = (Graphics2D) g.create();
        
        // 设置抗锯齿
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
        
        // 计算圆角矩形区域
        int width = getWidth();
        int height = getHeight();
        
        // 填充背景
        g2d.setColor(BG_COLOR);
        g2d.fill(new RoundRectangle2D.Double(0, 0, width, height, CORNER_RADIUS, CORNER_RADIUS));
        
        // 绘制边框
        g2d.setColor(BORDER_COLOR);
        g2d.setStroke(new BasicStroke(1.0f));
        g2d.draw(new RoundRectangle2D.Double(0, 0, width - 1, height - 1, CORNER_RADIUS, CORNER_RADIUS));
        
        g2d.dispose();
    }
    
    public InputBoxScrollPane getInputBoxScrollPane() {
        return inputBoxScrollPane;
    }

    public void setInputBoxScrollPane(InputBoxScrollPane inputBoxScrollPane) {
        this.inputBoxScrollPane = inputBoxScrollPane;
    }
}
